import java.util.HashSet;
import java.util.Stack;

public class NodeTest {
    private int data;
    private NodeTest next;

    public NodeTest(){

    }

    public NodeTest(int data, NodeTest next) {
        this.data = data;
        this.next = next;
    }

    public int getData() {
        return data;
    }

    public void setData(int data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "NodeTest{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }

    public static void main(String[] args) {
        ListNode l1 = new ListNode(1);

        ListNode l2 = new ListNode(3);
        ListNode l3 = new ListNode(2);
        reversePrint(l1);
    }

    public static int[] reversePrint(ListNode head) {
        Stack<ListNode> stack = new Stack<ListNode>();
        ListNode temp = head;
        while(temp != null){
            stack.push(temp);
            temp = temp.next;
        }
        System.out.println(stack.size());
        int[] result = new int[stack.size()];
        for(int i = 0;i<stack.size();i++){
            result[i] = stack.pop().val;
        }
        return result;

    }
}
class ListNode {
 int val;
  ListNode next;
  ListNode(int x) { val = x; }}
